﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using FRMS.Model;

namespace FRMS
{
    public class DevicesGoto
    {
        public CHCNetSDK.NET_DVR_TIME m_struTimeCfg;
        public CHCNetSDK.NET_DVR_DEVICECFG_V40 m_struDeviceCfg;
        public CHCNetSDK.NET_DVR_NETCFG_V30 m_struNetCfg;

        public CHCNetSDK.NET_DVR_DEVICEINFO_V30 m_struDeviceInfo;
        public CHCNetSDK.NET_DVR_IPPARACFG_V40 m_struIpParaCfgV40;
        public bool m_bDeleteAll = true;
        public class CResponseStatus
        {
            public string requestURL { get; set; }
            public int statusCode { get; set; }
            public string statusString { get; set; }
            public string subStatusCode { get; set; }
            public int errorCode { get; set; }
            public string errorMsg { get; set; }
            public string FPID { get; set; }
        }
        public class CFaceRecordDelete
        {
            public List<CFPID> FPID { get; set; }
        }

        public class CFPID
        {
            public string value { get; set; }
        }
        public class CCardInfoCount
        {
            public CCardInfoCountContent CardInfoCount { get; set; }
        }

        public class CCardInfoCountContent
        {
            public int cardNumber { get; set; }
        }
        public class CFaceRecordCount
        {
            public string requestURL { get; set; }
            public int statusCode { get; set; }
            public string statusString { get; set; }
            public string subStatusCode { get; set; }
            public int errorCode { get; set; }
            public string errorMsg { get; set; }
            public string FDID { get; set; }
            public string faceLibType { get; set; }
            public int recordDataNumber { get; set; }
        }
        public string[] arrayDevicesInfo = new string[7];
        public bool DevicesTimeSet(int m_lUserID)
        {
            //NET_DVR_Init();
            //DevicesConnect(DevicesIP);
            //m_lUserID = CHCNetSDK.NET_DVR_Login_V30("172.16.1.200", 8000, "admin", "admin123456", ref m_struDeviceInfo);
            if (m_lUserID == -1)
            {
                return false;
                //登录失败
                //return Content("登录失败");
            }
            else
            {
                bool result = btnTimeSet(m_lUserID);
                return result;
            }
        }
        //设置设备时间
        public bool btnTimeSet(int m_lUserID)
        {
            m_struTimeCfg.dwYear = Int32.Parse(DateTime.Now.Year.ToString());
            m_struTimeCfg.dwMonth = Int32.Parse(DateTime.Now.Month.ToString());
            m_struTimeCfg.dwDay = Int32.Parse(DateTime.Now.Day.ToString());
            m_struTimeCfg.dwHour = Int32.Parse(DateTime.Now.Hour.ToString());
            m_struTimeCfg.dwMinute = Int32.Parse(DateTime.Now.Minute.ToString());
            m_struTimeCfg.dwSecond = Int32.Parse(DateTime.Now.Second.ToString());

            Int32 nSize = Marshal.SizeOf(m_struTimeCfg);
            IntPtr ptrTimeCfg = Marshal.AllocHGlobal(nSize);
            Marshal.StructureToPtr(m_struTimeCfg, ptrTimeCfg, false);

            if (!CHCNetSDK.NET_DVR_SetDVRConfig(m_lUserID, CHCNetSDK.NET_DVR_SET_TIMECFG, -1, ptrTimeCfg, (UInt32)nSize))
            {
                //iLastErr = CHCNetSDK.NET_DVR_GetLastError();
                //strErr = "NET_DVR_SET_TIMECFG failed, error code= " + iLastErr;
                //设置时间失败，输出错误号 Failed to set the time of device and output the error code
                //MessageBox.Show(strErr);
                Marshal.FreeHGlobal(ptrTimeCfg);
                return false;
            }
            else
            {
                //MessageBox.Show("校时成功！");
                Marshal.FreeHGlobal(ptrTimeCfg);
                return true;
            }


        }

        public string btnDevCfgGet(int m_lUserID)
        {
            //string DecinfoA1;
            UInt32 dwReturn = 0;
            Int32 nSize = Marshal.SizeOf(m_struDeviceCfg);
            IntPtr ptrDeviceCfg = Marshal.AllocHGlobal(nSize);
            Marshal.StructureToPtr(m_struDeviceCfg, ptrDeviceCfg, false);
            if (!CHCNetSDK.NET_DVR_GetDVRConfig(m_lUserID, CHCNetSDK.NET_DVR_GET_DEVICECFG_V40, -1, ptrDeviceCfg, (UInt32)nSize, ref dwReturn))
            {
                //iLastErr = CHCNetSDK.NET_DVR_GetLastError();
                //strErr = "NET_DVR_GET_DEVICECFG_V40 failed, error code= " + iLastErr;
                //获取设备参数失败，输出错误号 Failed to get the basic parameters of device and output the error code
                Marshal.FreeHGlobal(ptrDeviceCfg);
                return ("");
            }
            else
            {
                m_struDeviceCfg = (CHCNetSDK.NET_DVR_DEVICECFG_V40)Marshal.PtrToStructure(ptrDeviceCfg, typeof(CHCNetSDK.NET_DVR_DEVICECFG_V40));
                //string DecinfoA;
                //Devices OwnerP = new Devices();
                //Response.Write("<script language=javascript>alert('123')</script>");
                //DecinfoA1  = Encoding.GetEncoding("GBK").GetString(m_struDeviceCfg.sDVRName);
                //Response.Write(DecinfoA1);
                //string DecinfoA = Encoding.UTF8.GetString(m_struDeviceCfg.byDevTypeName);
                //string DecinfoA2 = Convert.ToString(m_struDeviceCfg.byChanNum);
                //DecinfoA = Convert.ToString(m_struDeviceCfg.byIPChanNum + 256 * m_struDeviceCfg.byHighIPChanNum);
                //DecinfoA = Convert.ToString(m_struDeviceCfg.byZeroChanNum);
                //arrayDevicesInfo[0] = Convert.ToString(m_struDeviceCfg.byNetworkPortNum);
                //DecinfoA = Convert.ToString(m_struDeviceCfg.byAlarmInPortNum);
                //DecinfoA = Convert.ToString(m_struDeviceCfg.byAlarmOutPortNum);
                //DecinfoA = System.Text.Encoding.UTF8.GetString(m_struDeviceCfg.sSerialNumber);

                uint iVer1 = (m_struDeviceCfg.dwSoftwareVersion >> 24) & 0xFF;
                uint iVer2 = (m_struDeviceCfg.dwSoftwareVersion >> 16) & 0xFF;
                uint iVer3 = m_struDeviceCfg.dwSoftwareVersion & 0xFFFF;
                uint iVer4 = (m_struDeviceCfg.dwSoftwareBuildDate >> 16) & 0xFFFF;
                uint iVer5 = (m_struDeviceCfg.dwSoftwareBuildDate >> 8) & 0xFF;
                uint iVer6 = m_struDeviceCfg.dwSoftwareBuildDate & 0xFF;
                //版本号
                arrayDevicesInfo[0] = "V" + iVer1 + "." + iVer2 + "." + iVer3 + " Build " + string.Format("{0:D2}", iVer4) + string.Format("{0:D2}", iVer5) + string.Format("{0:D2}", iVer6);
                //return Content (DecinfoA2);
                Marshal.FreeHGlobal(ptrDeviceCfg);
                return arrayDevicesInfo[0];//返回设备版本号
            }


        }

        //获取设备网络参数信息---IP\掩码\网关\DNS
        //public string[] btnNetCfgGet(int m_lUserID)
        //{
        //    UInt32 dwReturn = 0;
        //    Int32 nSize = Marshal.SizeOf(m_struNetCfg);
        //    IntPtr ptrNetCfg = Marshal.AllocHGlobal(nSize);
        //    Marshal.StructureToPtr(m_struNetCfg, ptrNetCfg, false);

        //    if (!CHCNetSDK.NET_DVR_GetDVRConfig(m_lUserID, CHCNetSDK.NET_DVR_GET_NETCFG_V30, -1, ptrNetCfg, (UInt32)nSize, ref dwReturn))
        //    {
        //        //iLastErr = CHCNetSDK.NET_DVR_GetLastError();
        //        //strErr = "NET_DVR_GET_NETCFG_V30 failed, error code= " + iLastErr;
        //        //获取网络参数失败，输出错误号 Failed to get the network parameters and output the error code
        //        Marshal.FreeHGlobal(ptrNetCfg);
        //        return arrayDevicesInfo;
        //    }
        //    else
        //    {
        //        Devices DeviceInfo = new Devices();
        //        m_struNetCfg = (CHCNetSDK.NET_DVR_NETCFG_V30)Marshal.PtrToStructure(ptrNetCfg, typeof(CHCNetSDK.NET_DVR_NETCFG_V30));
        //        arrayDevicesInfo[2] = m_struNetCfg.struEtherNet[0].struDVRIP.sIpV4;//设备IP
        //        arrayDevicesInfo[3] = m_struNetCfg.struGatewayIpAddr.sIpV4;//子网掩码
        //        arrayDevicesInfo[4] = m_struNetCfg.struEtherNet[0].struDVRIPMask.sIpV4;//网关
        //        arrayDevicesInfo[5] = m_struNetCfg.struDnsServer1IpAddr.sIpV4;//DNS
        //        Marshal.FreeHGlobal(ptrNetCfg);
        //        return arrayDevicesInfo;
        //    }

        //}

        //设置网络参数信息
        public void btnNetCfgSet()
        {
            //m_struNetCfg.struEtherNet[0].struDVRIP.sIpV4 = textBoxIPAddr.Text;
            //m_struNetCfg.struGatewayIpAddr.sIpV4 = textBoxGateWay.Text;
            //m_struNetCfg.struEtherNet[0].struDVRIPMask.sIpV4 = textBoxSubMask.Text;
            //m_struNetCfg.struDnsServer1IpAddr.sIpV4 = textBoxDns.Text;
            //m_struNetCfg.wHttpPortNo = UInt16.Parse(textBoxHttpCfg.Text);
            //m_struNetCfg.struEtherNet[0].wDVRPort = UInt16.Parse(textBoxSdkCfg.Text);
            //m_struNetCfg.struAlarmHostIpAddr.sIpV4 = textBoxHostIP.Text;
            //m_struNetCfg.wAlarmHostIpPort = UInt16.Parse(textBoxHostPort.Text);

            //if (checkBoxDhcp.Checked)
            //{
            //    if (m_struNetCfg.struPPPoE.dwPPPOE == 1)
            //    {
            //        MessageBox.Show("设备PPPoE已启用，需要先禁用PPPoE才能启动DHCP自动获取IP！");
            //        checkBoxDhcp.Checked = false;
            //    }
            //    else
            //        m_struNetCfg.byUseDhcp = 1;
            //}
            //else
            //{
            //    m_struNetCfg.byUseDhcp = 0;
            //}

            //if (checkBoxPPPoe.Checked)
            //{
            //    m_struNetCfg.struPPPoE.dwPPPOE = 1;
            //    byte[] byName = System.Text.Encoding.Default.GetBytes(textBoxPPPoeName.Text);
            //    m_struNetCfg.struPPPoE.sPPPoEUser = new byte[32];
            //    byName.CopyTo(m_struNetCfg.struPPPoE.sPPPoEUser, 0);
            //    m_struNetCfg.struPPPoE.sPPPoEPassword = textBoxPPPoEPsw.Text;
            //}
            //else
            //{
            //    m_struNetCfg.struPPPoE.dwPPPOE = 0;
            //}

            //Int32 nSize = Marshal.SizeOf(m_struNetCfg);
            //IntPtr ptrNetCfg = Marshal.AllocHGlobal(nSize);
            //Marshal.StructureToPtr(m_struNetCfg, ptrNetCfg, false);

            //if (!CHCNetSDK.NET_DVR_SetDVRConfig(m_lUserID, CHCNetSDK.NET_DVR_SET_NETCFG_V30, -1, ptrNetCfg, (UInt32)nSize))
            //{
            //    iLastErr = CHCNetSDK.NET_DVR_GetLastError();
            //    strErr = "NET_DVR_SET_NETCFG_V30 failed, error code= " + iLastErr;
            //    //设置网络参数失败，输出错误号 Failed to set the network parameters and output the error code
            //    MessageBox.Show(strErr);
            //}
            //else
            //{
            //    MessageBox.Show("设置网络参数成功！");
            //}
            //Marshal.FreeHGlobal(ptrNetCfg);
        }

        //获取设备日期时间
        public void btnTimeGet(int m_lUserID)
        {
            UInt32 dwReturn = 0;
            Int32 nSize = Marshal.SizeOf(m_struTimeCfg);
            IntPtr ptrTimeCfg = Marshal.AllocHGlobal(nSize);
            Marshal.StructureToPtr(m_struTimeCfg, ptrTimeCfg, false);
            if (!CHCNetSDK.NET_DVR_GetDVRConfig(m_lUserID, CHCNetSDK.NET_DVR_GET_TIMECFG, -1, ptrTimeCfg, (UInt32)nSize, ref dwReturn))
            {
                //iLastErr = CHCNetSDK.NET_DVR_GetLastError();
                //strErr = "NET_DVR_GET_TIMECFG failed, error code= " + iLastErr;
                //获取设备时间失败，输出错误号 Failed to get time of the device and output the error code
                //MessageBox.Show(strErr);
            }
            else
            {
                m_struTimeCfg = (CHCNetSDK.NET_DVR_TIME)Marshal.PtrToStructure(ptrTimeCfg, typeof(CHCNetSDK.NET_DVR_TIME));
                //textBoxYear.Text = Convert.ToString(m_struTimeCfg.dwYear);
                //textBoxMonth.Text = Convert.ToString(m_struTimeCfg.dwMonth);
                //textBoxDay.Text = Convert.ToString(m_struTimeCfg.dwDay);
                //textBoxHour.Text = Convert.ToString(m_struTimeCfg.dwHour);
                //textBoxMinute.Text = Convert.ToString(m_struTimeCfg.dwMinute);
                //textBoxSecond.Text = Convert.ToString(m_struTimeCfg.dwSecond);
                arrayDevicesInfo[6] = m_struTimeCfg.dwYear + "-" + m_struTimeCfg.dwMonth + "-" + m_struTimeCfg.dwDay + " " +
                    m_struTimeCfg.dwHour + ":" + m_struTimeCfg.dwMinute + ":" + m_struTimeCfg.dwSecond;
            }
            Marshal.FreeHGlobal(ptrTimeCfg);
        }

        //获取设备存储的卡数量
        public int GetAllCardCount(int m_lUserID, string Userid)
        {
            //NET_DVR_Init();
            //DevicesConnect(DevicesIP);
            IntPtr ptrOutBuf = Marshal.AllocHGlobal(1024);
            IntPtr ptrStatusBuffer = Marshal.AllocHGlobal(1024);

            for (int i = 0; i < 1024; i++)
            {
                Marshal.WriteByte(ptrOutBuf, i, 0);
                Marshal.WriteByte(ptrStatusBuffer, i, 0);
            }

            CHCNetSDK.NET_DVR_XML_CONFIG_INPUT struInput = new CHCNetSDK.NET_DVR_XML_CONFIG_INPUT();
            CHCNetSDK.NET_DVR_XML_CONFIG_OUTPUT struOuput = new CHCNetSDK.NET_DVR_XML_CONFIG_OUTPUT();
            string sUrl;
            if (Userid == "")
            {
                sUrl = "GET /ISAPI/AccessControl/CardInfo/Count?format=json";
            }
            else
            {
                sUrl = "GET /ISAPI/AccessControl/CardInfo/Count?format=json&employeeNo=" + Userid;
            }
            IntPtr ptrURL = Marshal.StringToHGlobalAnsi(sUrl);
            struInput.dwSize = (uint)Marshal.SizeOf(struInput);
            struInput.lpRequestUrl = ptrURL;
            struInput.dwRequestUrlLen = (uint)sUrl.Length;

            struOuput.dwSize = (uint)Marshal.SizeOf(struOuput);
            struOuput.lpOutBuffer = ptrOutBuf;
            struOuput.dwOutBufferSize = 1024;
            struOuput.lpStatusBuffer = ptrStatusBuffer;
            struOuput.dwStatusSize = 1024;

            IntPtr ptrInput = Marshal.AllocHGlobal(Marshal.SizeOf(struInput));
            Marshal.StructureToPtr(struInput, ptrInput, false);
            IntPtr ptrOuput = Marshal.AllocHGlobal(Marshal.SizeOf(struOuput));
            Marshal.StructureToPtr(struOuput, ptrOuput, false);
            if (!CHCNetSDK.NET_DVR_STDXMLConfig(m_lUserID, ptrInput, ptrOuput))
            {
                //ListViewItem listItem = new ListViewItem();
                //listItem.Text = "Fail";
                string strTemp = string.Format("Get Card Info Count Fail,Error Code={0}", CHCNetSDK.NET_DVR_GetLastError());
                //listItem.SubItems.Add(strTemp);
                //this.AddList(listViewMessage, listItem);
                Marshal.FreeHGlobal(ptrOutBuf);
                Marshal.FreeHGlobal(ptrStatusBuffer);
                Marshal.FreeHGlobal(ptrInput);
                Marshal.FreeHGlobal(ptrOuput);
                Marshal.FreeHGlobal(ptrURL);
                return 0;
            }
            else
            {
                //ListViewItem listItem = new ListViewItem();
                //listItem.Text = "Succ";
                string strTemp = string.Format("Get Card Info Count Success");
                //listItem.SubItems.Add(strTemp);
                //this.AddList(listViewMessage, listItem);

                string strCardInfoCount = Marshal.PtrToStringAnsi(struOuput.lpOutBuffer);
                CCardInfoCount JsonCardInfoCount = new CCardInfoCount();
                JsonCardInfoCount = JsonConvert.DeserializeObject<CCardInfoCount>(strCardInfoCount);
                Marshal.FreeHGlobal(ptrOutBuf);
                Marshal.FreeHGlobal(ptrStatusBuffer);
                Marshal.FreeHGlobal(ptrInput);
                Marshal.FreeHGlobal(ptrOuput);
                Marshal.FreeHGlobal(ptrURL);
                return JsonCardInfoCount.CardInfoCount.cardNumber;
            }


        }
        public int FaceGetByFDID(int m_lUserID)
        {
            //NET_DVR_Init();
            //DevicesConnect(DevicesIP);
            IntPtr ptrOutBuf = Marshal.AllocHGlobal(1024);
            IntPtr ptrStatusBuffer = Marshal.AllocHGlobal(1024);

            for (int i = 0; i < 1024; i++)
            {
                Marshal.WriteByte(ptrOutBuf, i, 0);
                Marshal.WriteByte(ptrStatusBuffer, i, 0);
            }

            CHCNetSDK.NET_DVR_XML_CONFIG_INPUT struInput = new CHCNetSDK.NET_DVR_XML_CONFIG_INPUT();
            CHCNetSDK.NET_DVR_XML_CONFIG_OUTPUT struOuput = new CHCNetSDK.NET_DVR_XML_CONFIG_OUTPUT();

            string sUrl = "GET /ISAPI/Intelligent/FDLib/Count?format=json&FDID=1&faceLibType=blackFD";
            IntPtr ptrURL = Marshal.StringToHGlobalAnsi(sUrl);
            struInput.dwSize = (uint)Marshal.SizeOf(struInput);
            struInput.lpRequestUrl = ptrURL;
            struInput.dwRequestUrlLen = (uint)sUrl.Length;

            struOuput.dwSize = (uint)Marshal.SizeOf(struOuput);
            struOuput.lpOutBuffer = ptrOutBuf;
            struOuput.dwOutBufferSize = 1024;
            struOuput.lpStatusBuffer = ptrStatusBuffer;
            struOuput.dwStatusSize = 1024;

            IntPtr ptrInput = Marshal.AllocHGlobal(Marshal.SizeOf(struInput));
            Marshal.StructureToPtr(struInput, ptrInput, false);
            IntPtr ptrOuput = Marshal.AllocHGlobal(Marshal.SizeOf(struOuput));
            Marshal.StructureToPtr(struOuput, ptrOuput, false);
            if (!CHCNetSDK.NET_DVR_STDXMLConfig(m_lUserID, ptrInput, ptrOuput))
            {
                //ListViewItem listItem = new ListViewItem();
                //listItem.Text = "Fail";
                //string strTemp = string.Format("Get Face Record Count Fail,Error Code={0}", CHCNetSDK.NET_DVR_GetLastError());
                //listItem.SubItems.Add(strTemp);
                //this.AddList(listViewMessage, listItem);
                Marshal.FreeHGlobal(ptrOutBuf);
                Marshal.FreeHGlobal(ptrStatusBuffer);
                Marshal.FreeHGlobal(ptrInput);
                Marshal.FreeHGlobal(ptrOuput);
                Marshal.FreeHGlobal(ptrURL);
                return 0;
            }
            else
            {
                string strFaceRecordCount = Marshal.PtrToStringAnsi(struOuput.lpOutBuffer);
                CFaceRecordCount JsonFaceRecordCount = new CFaceRecordCount();
                JsonFaceRecordCount = JsonConvert.DeserializeObject<CFaceRecordCount>(strFaceRecordCount);
                int iRecordDataNumber = JsonFaceRecordCount.recordDataNumber;
                //textBoxRecordDataNumber.Text = iRecordDataNumber.ToString();
                Marshal.FreeHGlobal(ptrOutBuf);
                Marshal.FreeHGlobal(ptrStatusBuffer);
                Marshal.FreeHGlobal(ptrInput);
                Marshal.FreeHGlobal(ptrOuput);
                Marshal.FreeHGlobal(ptrURL);
                //return Content("Succ!Count=" + iRecordDataNumber.ToString());
                return iRecordDataNumber;
            }


        }//获取设备端下发的人脸数量
        public bool DeleteFaceRecord(int m_lUserID, string EmployeeNo)
        {//EmployeeNo为空则删除所有人脸,否则按工号删除人脸
            IntPtr ptrOutBuf = Marshal.AllocHGlobal(1024);
            IntPtr ptrStatusBuffer = Marshal.AllocHGlobal(1024);

            for (int i = 0; i < 1024; i++)
            {
                Marshal.WriteByte(ptrOutBuf, i, 0);
                Marshal.WriteByte(ptrStatusBuffer, i, 0);
            }

            CHCNetSDK.NET_DVR_XML_CONFIG_INPUT struInput = new CHCNetSDK.NET_DVR_XML_CONFIG_INPUT();
            CHCNetSDK.NET_DVR_XML_CONFIG_OUTPUT struOuput = new CHCNetSDK.NET_DVR_XML_CONFIG_OUTPUT();

            string sUrl = "PUT /ISAPI/Intelligent/FDLib/FDSearch/Delete?format=json&FDID=1&faceLibType=blackFD";
            IntPtr ptrURL = Marshal.StringToHGlobalAnsi(sUrl);
            struInput.dwSize = (uint)Marshal.SizeOf(struInput);
            struInput.lpRequestUrl = ptrURL;
            struInput.dwRequestUrlLen = (uint)sUrl.Length;

            CFaceRecordDelete JsonFaceRecordDelete = new CFaceRecordDelete();
            JsonFaceRecordDelete.FPID = new List<CFPID>();

            if (EmployeeNo != "")
            {
                //foreach (ListViewItem item in this.listViewFPID.Items)
                //{
                //    if (item.SubItems[1].Text != "")
                //    {
                CFPID singleFPID = new CFPID();
                singleFPID.value = EmployeeNo;//工号
                JsonFaceRecordDelete.FPID.Add(singleFPID);
                //    }
                //}
            }

            string strFaceRecordDelete = JsonConvert.SerializeObject(JsonFaceRecordDelete);

            IntPtr ptrInBuffer = Marshal.StringToHGlobalAnsi(strFaceRecordDelete);

            struInput.lpInBuffer = ptrInBuffer;
            struInput.dwInBufferSize = (uint)strFaceRecordDelete.Length;

            struOuput.dwSize = (uint)Marshal.SizeOf(struOuput);
            struOuput.lpOutBuffer = ptrOutBuf;
            struOuput.dwOutBufferSize = 1024;
            struOuput.lpStatusBuffer = ptrStatusBuffer;
            struOuput.dwStatusSize = 1024;

            IntPtr ptrInput = Marshal.AllocHGlobal(Marshal.SizeOf(struInput));
            Marshal.StructureToPtr(struInput, ptrInput, false);
            IntPtr ptrOuput = Marshal.AllocHGlobal(Marshal.SizeOf(struOuput));
            Marshal.StructureToPtr(struOuput, ptrOuput, false);
            if (!CHCNetSDK.NET_DVR_STDXMLConfig(m_lUserID, ptrInput, ptrOuput))
            {
                //ListViewItem listItem = new ListViewItem();
                //listItem.Text = "Fail";
                //string strTemp = string.Format("Delete Face Record Fail,Error Code={0}", CHCNetSDK.NET_DVR_GetLastError());
                //listItem.SubItems.Add(strTemp);
                //this.AddList(listViewMessage, listItem);
                return false;
            }
            else
            {
                //ListViewItem listItem = new ListViewItem();
                //listItem.Text = "Succ";
                //string strTemp = string.Format("Delete Face Record Success");
                //listItem.SubItems.Add(strTemp);
                //this.AddList(listViewMessage, listItem);

                string strResponseStatus = Marshal.PtrToStringAnsi(struOuput.lpOutBuffer);
                CResponseStatus JsonResponseStatus = new CResponseStatus();
                JsonResponseStatus = JsonConvert.DeserializeObject<CResponseStatus>(strResponseStatus);

            }

            Marshal.FreeHGlobal(ptrOutBuf);
            Marshal.FreeHGlobal(ptrStatusBuffer);
            Marshal.FreeHGlobal(ptrInBuffer);
            Marshal.FreeHGlobal(ptrInput);
            Marshal.FreeHGlobal(ptrOuput);
            Marshal.FreeHGlobal(ptrURL);
            return true;
        }
        public string errreturn(int errno)
        {
            string content = "";
            switch (errno)
            {
                case 1001:
                    content = "没有符合条件的记录！";
                    break;
                case 1002:
                    content = "修改成功";
                    break;
                case 1003:
                    content = "修改失败";
                    break;

                case 1004:
                    content = "添加成功";
                    break;
                case 1005:
                    content = "添加失败";
                    break;
                case 1006:
                    content = "删除成功";
                    break;
                case 1007:
                    content = "删除失败";
                    break;
                case 1008:
                    content = "卡号绑定成功";
                    break;
                case 1009:
                    content = "卡号绑定失败";
                    break;
                case 1010:
                    content = "设备上删除该用户失败";
                    break;
            }
            return content;//返回错误说明
        }
    }
}
